package com.oa.gform.client.service;

import java.io.Serializable;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/***
 * Gestore delle callback RPC.
 * Questa classe implementa una gestione automatica delle eccezioni rialzate dal server.
 * @author Marco
 *
 * @param <T>
 */
@RemoteServiceRelativePath("GFormBeanProxyService")
public abstract class GFormSuccessAsyncCallback<T extends Serializable> implements AsyncCallback<T> {
	boolean showError = true;
	protected abstract void onSuccessInternal(T result); 

	public GFormSuccessAsyncCallback() {
	}
	
	public GFormSuccessAsyncCallback(boolean showError) {
		this.showError = showError;
	}
	
	public void onFailure(Throwable caught) {
		try {
			caught.printStackTrace();
			if (showError) {
				Window.alert(caught.getMessage());
			}	
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void onSuccess(T result) {
		onSuccessInternal(result);
	}
	
}
